#ifndef _LOOPBUF_H_
#define _LOOPBUF_H_

#include "common.h"
#include <semaphore.h>

typedef struct
{
	u8   *buf;
	u32  unitNum;
	u32  unitLen;
	u32  rpos;
	u32  wpos;
	pthread_mutex_t lock;
	sem_t rsem;
	sem_t wsem;
}ifly_msgQ_t;

typedef struct
{
	u8   *buf;
#ifdef CJ_3GTEST
	u32 *buf_start;
	u32 *buf_num;
	u32 *buf_jump;
	u32 msgnum;
	u32 free_pos;
	u32 used_pos;
	u32 free_num;
	u32 new_stamp;
	u32 last_stamp;
#endif
	u32  unitNum;
	u32  unitLen;
	u32  rpos;
	u32  wpos;
	pthread_mutex_t lock;
	sem_t rsem;
	sem_t wsem;
}ifly_udp_msgQ_t;

#ifdef __cplusplus
extern "C" {
#endif

BOOL initMsgQ(ifly_msgQ_t *mq,u32 unitNum,u32 unitLen);
int  readMsgQ(ifly_msgQ_t *mq,u8 *pBuf,u32 readLen);
int  writeMsgQ(ifly_msgQ_t *mq,u8 *pBuf,u32 writeLen);
BOOL destroyMsgQ(ifly_msgQ_t *mq);

BOOL GetMsgQReadInfo(ifly_msgQ_t *mq,u8 **ppBuf,u32 *pReadLen);
BOOL GetMsgQReadInfo2(ifly_msgQ_t *mq,u8 **ppBuf,u32 *pReadLen);
BOOL skipReadMsgQ(ifly_msgQ_t *mq);

BOOL GetMsgQWriteInfo(ifly_msgQ_t *mq,u8 **ppBuf,u32 *pWriteLen);
BOOL skipWriteMsgQ(ifly_msgQ_t *mq);

u32 getReadPosMsgQ(ifly_msgQ_t *mq);

#ifdef __cplusplus
}
#endif

#endif
